import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';

import 'package:hockey/jzx_models.dart';
import 'package:hockey/network/jzx_apis.dart';

part 'jzx_api_client.g.dart';

/// https://pub.dev/packages/retrofit
@RestApi()
abstract class ApiClient {
  factory ApiClient(Dio dio, {String baseUrl}) = _ApiClient;

  /// 退出登录
  @POST(kApiDeleteAccount)
  Future deleteAccount();

  /// 退出登录
  @POST(kApiLogout)
  Future logout();

  /// 登录
  @POST(kApiLogin)
  @FormUrlEncoded()
  Future<JzxTokenData> login(@Body() Map<String, dynamic> params);

  /// 获取用户信息
  @GET(kApiGetUserInfo)
  Future<JzxUserData> user(@Query('userId') String uid);

  /// 验证token
  @POST(kApiValidToken)
  Future validToken(@Body() Map<String, dynamic> params);

  /// 埋点
  @POST(kApiEventTracking)
  Future eventTracking(@Body() List<Map<String, dynamic>> params);

  /// 获取配置
  @GET(kApiGetAppConfig)
  Future<JzxConfigData> getAppConfig();

  ///GET 登录完成后，使用rck的融云key进行IM初始化功能后，再使用该接口返回的token进行IM连接。
  @GET(kApiGetRCToken)
  Future getRCToken();

  /// 退出登录
  @POST(kApiVideoSearch)
  Future<List<JzxVideoData>> videoSearch(
      @Body() List<Map<String, dynamic>> params);

  /// 用户列表
  @POST(kApiBroadcasterWall)
  Future<List<JzxAuthorData>> broadcasterWall(
      @Body() Map<String, dynamic> params);

  /// 举报\拉黑接口
  /// ```
  /// {
  ///   'broadcasterId':'',
  ///   'complainCategory':'',block / Report
  ///   'complainSub':'',
  /// }
  /// ```
  @POST(kApiAddBlock)
  Future addBlock(@Body() Map<String, dynamic> params);

  /// 移除拉黑
  ///   'broadcasterId':'',
  @POST(kApiRemoveBlock)
  Future removeBlock(@Body() Map<String, dynamic> params);

  /// 拉黑列表
  @POST(kApiBlockList)
  Future<List<JzxBlockData>> blockList();

  /// 关注\取消关注接口
  ///   'followUserId':'',
  @POST(kApiAddFollow)
  Future addFollow(@Body() Map<String, dynamic> params);

  /// 移除拉黑
  ///   'followUserId':'',
  @POST(kApiRemoveFollow)
  Future removeFollow(@Body() Map<String, dynamic> params);

  /// 获取关注列表接口
  @POST(kApiFollowList)
  Future<List<JzxFollowData>> followList(@Body() Map<String, dynamic> params);

  /// 获取oss上传策略
  @GET(kApiOssPolicy)
  Future ossPolicy();

  /// 更新用户头像
  @POST(kApiUpdateAvatar)
  Future<JzxAvatarData> updateAvatar(@Body() Map<String, dynamic> params);

  /// 更新用户
  @POST(kApiSaveUserInfo)
  Future saveUserInfo(@Body() Map<String, dynamic> params);

  /// 商品列表
  @POST(kApiGoodsList)
  Future<List<JzxGoodsData>> goodsList(@Body() Map<String, dynamic> params);

  /// 创建充值订单接口
  @POST(kApiCreateOrder)
  Future<JzxOrderData> createOrder(@Body() Map<String, dynamic> params);

  /// 验单接口
  @POST(kApiIpaPay)
  Future verifyPayment(@Body() Map<String, dynamic> params);

  /// 消费扣除金币
  @POST(kApiConsume)
  Future consume(@Body() Map<String, dynamic> params);

  // @GET('https://api.thecatapi.com/v1/images/search')
  // Future<List<ArticleModel>> getArticle(
  //   @Query('limit') int limit,
  // );
  // Future<List<ArticleModel>> getArticle(@Queries() Map<String, dynamic> query);
}

extension MapExt on Map<String, dynamic> {
  Map<String, dynamic> toJson() {
    return this;
  }
}

/**
 *   @GET('/tasks/{id}')
  Future<Task> getTask(@Path('id') String id);
  
  @GET('/demo')
  Future<String> queries(@Queries() Map<String, dynamic> queries);
  
  @GET('https://httpbin.org/get')
  Future<String> namedExample(
      @Query('apikey') String apiKey,
      @Query('scope') String scope,
      @Query('type') String type,
      @Query('from') int from);
  
  @PATCH('/tasks/{id}')
  Future<Task> updateTaskPart(
      @Path() String id, @Body() Map<String, dynamic> map);
  
  @PUT('/tasks/{id}')
  Future<Task> updateTask(@Path() String id, @Body() Task task);
  
  @DELETE('/tasks/{id}')
  Future<void> deleteTask(@Path() String id);
  
  @POST('/tasks')
  Future<Task> createTask(@Body() Task task);
  
  @POST('http://httpbin.org/post')
  Future<void> createNewTaskFromFile(@Part() File file);
  
  @POST('http://httpbin.org/post')
  @FormUrlEncoded()
  Future<String> postUrlEncodedFormData(@Field() String hello);
 */
